//
//  BSHeaderRefreshView.m
//  BaiSi
//
//  Created by Sycamore on 16/5/7.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "BSHeaderRefreshView.h"

@interface BSHeaderRefreshView ()
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UILabel *willRefreshlabel;
@property (weak, nonatomic) IBOutlet UILabel *willRefreshTime;
@property (weak, nonatomic) IBOutlet UIImageView *willRefreshArrow;
@property (weak, nonatomic) IBOutlet UILabel *refreshTime;

@end

@implementation BSHeaderRefreshView

+ (instancetype)headerView
{
    return [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil]lastObject];
}

- (void)awakeFromNib
{
    _contentView.backgroundColor = BSTintColor;
    self.autoresizingMask = UIViewAutoresizingNone;
}

- (void)setIsVisible:(BOOL)isVisible
{
    _isVisible = isVisible;
    
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    fmt.dateFormat = @"HH:mm:ss";
    _willRefreshTime.text = [fmt stringFromDate:[NSDate date]];
    _refreshTime.text = [fmt stringFromDate:[NSDate date]];
    
    if (_isVisible) {
       _willRefreshlabel.text = @"松开立即刷新。。。";
        [UIView animateWithDuration:0.25 animations:^{
            _willRefreshArrow.transform = CGAffineTransformMakeRotation(-M_PI + 0.01);
        }];
    }else{
        _willRefreshlabel.text = @"下拉立即刷新。。。";
        [UIView animateWithDuration:0.2 animations:^{
            _willRefreshArrow.transform = CGAffineTransformIdentity;
        }];
    }
}

- (void)setIsLoading:(BOOL)isLoading
{
    _isLoading = isLoading;
    
    _contentView.hidden = isLoading;
}
@end
